<template>
  <div>
    <el-dialog
      :visible.sync="visible"
      :width="width"
      :fullscreen="fullscreen"
      @close="close"
    >
      <div slot="title" class="dialog-title">
        {{ title }}
        <i :class="topIcon" @click="handleIcon"></i>
      </div>
      <div>
        <slot></slot>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="visibleSure">{{ sureBtn }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "dialog",
  props: {
    title: String,
    value: {
      type: Boolean,
      default: () => false,
    },
    width: {
      type: String,
      default: () => "70%",
    },
    sureBtn: {
      type: String,
      default: () => "保存",
    },
    fullscreen: {
      type: Boolean,
      default: () => false,
    },
    topIcon: {
      type: String,
    },
  },
  data() {
    return {
      visible: this.value,
    };
  },
  watch: {
    value() {
      this.visible = this.value;
    },
    visible: {
      handler(newName) {
        this.$emit('input',newName);
      },
    },
  },
  methods: {
    visibleSure() {
      this.$emit("confirm");
    },
    close() {
      this.$emit("close");
    },
    cancel() {
      this.$emit("cancel");
      setTimeout(() => {
        this.visible = false;
      }, 0);
    },
    handleIcon() {
      this.$emit("handleIcon");
    }
  },
};
</script>

<style lang="less" scoped>
.dialog2 {
  position: absolute;
  right: 40px;
  margin: auto;
}
</style>
